<template>
  <div class="user">
    <h2></h2>
    <basic-container>
      <avue-crud
        :option="option"
        ref="crud"
        v-model="form"
        :page="page"
        :simple-page="true"
        @size-change="sizeChange"
        @current-change="currentChange"
        :table-loading="listLoading"
        @search-change="handleFilter"
        @search-reset="handleRefreshChange"
        @refresh-change="handleRefreshChange"
        :before-open="handleOpenBefore"
        :data="list"
      >
        <template slot-scope="scope" slot="create_timeSearch">
          <el-date-picker
            v-model="searchDate"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </template>
        <template slot="is_vip" slot-scope="scope">
          <el-switch
            :value="Boolean(scope.row.is_vip === 0)"
            @change="changeFlagVip(scope.row.is_vip, scope.row.id)"
            active-color="#ff4949"
            inactive-color="#13ce66"
          >
          </el-switch>
        </template>
        <template slot="status" slot-scope="scope">
          <el-switch
            :value="Boolean(scope.row.status === 0)"
            @change="changeFlagStatus(scope.row.status, scope.row.id)"
            active-color="#ff4949"
            inactive-color="#13ce66"
          >
          </el-switch>
        </template>
        <template slot="end_time" slot-scope="scope">
          <span>
            {{scope.row.end_time | compareTime}}
          </span>
        </template>
        <template slot="menu" slot-scope="scope">
          <!-- <el-button
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row, scope.index)"
            >编辑
          </el-button> -->
          <!-- <el-button
            type="text"
            icon="el-icon-view"
            @click="handleview(scope.row, scope.index)"
            >查看详情
          </el-button> -->
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { authPayLog } from "@/api/admin/staff";
import { payLogOption } from "@/const/crud/admin/staff";
import { mapGetters } from "vuex";
import moment from 'moment'
import store from "@/store";

export default {
  data() {
    return {
      option: payLogOption,
      Authorization: {
        'access-token': store.getters.access_token
      },
      resultPage: {
        total: 0, // 总页数
        page: 1, // 当前页数
        limit: 10, // 每页显示多少条,
      },
      dialogFormVisible: false,
      resultList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20, // 每页显示多少条,
        isAsc: false //是否倒序
      },
      searchDate: '',
      list: [],
      listLoading: true,
      uploadUrl: '',
      form: {}
    };
  },
  computed: {
    ...mapGetters(["permissions", "access_token"])
  },
  watch: {
  },
  filters: {
    compareTime: function (value) {
      return moment(value).isBefore(moment())?'已到期':value
    }
  },
  created() {
    this.getList(this.page);
    this.uploadUrl = process.env.VUE_APP_BASE_API + "/upload/staffUpload";
    // this.sys_user_add = this.permissions["sys_user_add"];
    // this.sys_user_edit = this.permissions["sys_user_edit"];
    // this.sys_user_del = this.permissions["sys_user_del"];
  },
  methods: {
    getList(page, params) {
      this.listLoading = true;
      authPayLog(
        Object.assign(
          {
            page: page.currentPage,
            size: page.pageSize
          },
          params
        )
      ).then(response => {
        this.list = response.data.data.data;
        this.page.total = response.data.data.count || '0';
        this.listLoading = false;
      });
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.getList(this.page);
    },
    currentChange(current) {
      this.page.currentPage = current;
      this.getList(this.page);
    },
    handleFilter(param, done) {
      this.page.currentPage = 1;
      const qDate = {}
      if(this.searchDate){
        qDate.start = moment(this.searchDate[0]).format("YYYY-MM-DD HH:mm:ss")
        qDate.end = moment(this.searchDate[1]).format("YYYY-MM-DD HH:mm:ss")
      }
      this.getList(this.page, Object.assign(param, qDate));
      done();
    },
    handleRefreshChange() {
      this.searchDate = ''
      this.getList(this.page);
    },
    handleOpenBefore(show, type) {
      show();
    },
    changeState(row, status) {
      applyApproval({ id: row.id, status: status }).then(res => {
        this.getList(this.page);
      });
    },
    handleUpdate(row, index) {
      this.$refs.crud.rowEdit(row, index);
    },
    deletes(row) {
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        ExamRemove({ ids: row.id })
          .then(() => {
            this.getList(this.page);
            this.$notify.success("删除成功");
          })
          .catch(() => {
            this.$notify.error("删除失败");
          });
      });
    },
    handleview(data, index) {
      this.$refs.crud.rowView(data, index);
    },
  }
};
</script>
<style lang="less" scoped>
  .el-dialog__body {
    padding: 0 auto;
  }
</style>